﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Actuals.CoreDomain.Data;
using Actuals.CoreDomain;
using System.Data;
namespace Actuals.Data
{
    public class DalResourceProjection : Dal<IResourceProjection, ResourceProjection>, 
        IDalResourceProjection
    {
        private readonly IDalManager _manager;
        private static readonly IDalResourceProjection _instance = new DalResourceProjection();
        private const string SP_GET_ResourceProjection = "usp_ResourceProjection";

         public static IDalResourceProjection Instance
        {
            get { return _instance; }
        }

        public DalResourceProjection()
        {
            _manager = new DalManager();
        }

        public DalResourceProjection(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IResourceProjection obj, DataRow row)
        {
            obj.ProjectId = _manager.GetValue<int>(row, "ProjectId");
            obj.ReleaseId = _manager.GetValue<int>(row, "ReleaseId");
            obj.ProjectDescription = _manager.GetValue<string>(row, "ProjectDescription");
            obj.ReleaseDescription = _manager.GetValue<string>(row, "description");
            obj.NickName = _manager.GetValue<string>(row, "Nickname");
            obj.Id= _manager.GetValue<int>(row, "Id");
            obj.StartDate = _manager.GetValue<DateTime>(row, "StartDate");
            obj.EndDate = _manager.GetValue<DateTime>(row, "EndDate");
        }
        public IList<IResourceProjection> GetResourceProjection(string listOfEmpId, 
            DateTime startDate, DateTime endDate)
        {
            _manager.StoredProcedureName = SP_GET_ResourceProjection;
            _manager.AddInParameter("@empid", DbType.String, listOfEmpId);
            _manager.AddInParameter("@FromDate", DbType.DateTime, startDate);
            _manager.AddInParameter("@ToDate", DbType.DateTime, endDate);


            IResourceProjection resourceProjection = Convert(_manager.ExecuteDataSet());

            List<IResourceProjection> resourceProjections = new List<IResourceProjection>();
            foreach (IResourceProjection _resourceProjection in ConvertAll(_manager.ExecuteDataSet()))
                resourceProjections.Add(_resourceProjection);


            return resourceProjections;
        }
    }
}
